package com.ruoyi.question.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.question.domain.DtWrongQuestion;
import com.ruoyi.question.service.IDtWrongQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 错题管理Controller
 *
 * @author llc
 * @date 2025-01-07
 */
@RestController
@RequestMapping("/question/wrongquestion")
public class DtWrongQuestionController extends BaseController {
    @Autowired
    private IDtWrongQuestionService dtWrongQuestionService;


    /**
     * 查询错题管理列表
     */
    @PreAuthorize("@ss.hasPermi('question:wrongquestion:list')")
    @GetMapping("/list")
    public TableDataInfo list(DtWrongQuestion dtWrongQuestion) {
        startPage();
        List<DtWrongQuestion> list = dtWrongQuestionService.selectDtWrongQuestionList(dtWrongQuestion);
        return getDataTable(list);
    }

    /**
     * 导出错题管理列表
     */
    @PreAuthorize("@ss.hasPermi('question:wrongquestion:export')")
    @Log(title = "错题管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DtWrongQuestion dtWrongQuestion) {
        List<DtWrongQuestion> list = dtWrongQuestionService.selectDtWrongQuestionList(dtWrongQuestion);
        ExcelUtil<DtWrongQuestion> util = new ExcelUtil<DtWrongQuestion>(DtWrongQuestion.class);
        util.exportExcel(response, list, "错题管理数据");
    }

    /**
     * 获取错题管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('question:wrongquestion:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(dtWrongQuestionService.selectDtWrongQuestionById(id));
    }

    /**
     * 新增错题管理
     */
    @PreAuthorize("@ss.hasPermi('question:wrongquestion:add')")
    @Log(title = "错题管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DtWrongQuestion dtWrongQuestion) {
        return toAjax(dtWrongQuestionService.insertDtWrongQuestion(dtWrongQuestion));
    }

    /**
     * 修改错题管理
     */
    @PreAuthorize("@ss.hasPermi('question:wrongquestion:edit')")
    @Log(title = "错题管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DtWrongQuestion dtWrongQuestion) {
        return toAjax(dtWrongQuestionService.updateDtWrongQuestion(dtWrongQuestion));
    }

    /**
     * 删除错题管理
     */
    @PreAuthorize("@ss.hasPermi('question:wrongquestion:remove')")
    @Log(title = "错题管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(dtWrongQuestionService.deleteDtWrongQuestionByIds(ids));
    }
}
